/*
* Copyright © Shanghai Awinic Technology Co., Ltd. 2019 2020 . All rights reserved.
* Description: hdiv header file
* Date： 20201126
* Awinic_Version： aw_soc_driver_v1.0.0
*/
#include "compile_option.h"
#ifdef AW_86802

#include "aw8680x_global.h"

/**
  * @brief  HDIV initialization function
  * @param  None
  * @retval RET_STATUS_E status
  */
void hdiv_init(void)
{
	hdiv_clk_init();
}

/**
  * @brief  HDIV set parameters
  * @param  AW_U32 dividend : dividend, AW_U32 divisor : divisor
  * @retval None
  */
void hdiv_set_paras(AW_U32 dividend, AW_U32 divisor)
{
	HDIV->DIVIDEND = dividend;
	HDIV->DIVISOR = divisor;
}

/**
  * @brief  HDIV get result
  * @param  AW_U32 *p_quotient : point to quotient, AW_U32 *p_remainder : point to remainder
  * @retval RET_STATUS_E status
  */
RET_STATUS_E hdiv_get_res(AW_U32 *p_quotient, AW_U32 *p_remainder)
{
	if ((p_quotient == AW_NULL) || (p_remainder == AW_NULL)) {
		return RET_ERROR;
	}

	if (HDIV->DIVISOR == 0) {
		return RET_ERROR;
	} else {
		while (HDIV->DIVSTS == 0) {
		}
		*p_quotient = HDIV->DIVQUO;
		*p_remainder = HDIV->DIVREM;
	}
	return RET_OK;
}
#endif
